package com.bianguo.zsd.SpringBootDemo.service.impl;

import com.bianguo.zsd.SpringBootDemo.bean.User;
import com.bianguo.zsd.SpringBootDemo.dao.UserDao;
import com.bianguo.zsd.SpringBootDemo.service.UserService;
import com.bianguo.zsd.SpringBootDemo.utils.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

@Service
@EnableScheduling
public class UserServiceImpl implements UserService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserDao userDao;

    @Override
    public ArrayList<User> getUsers() {
        return userDao.queryUsers();
    }

    @Override
    public User getUserById(Integer id) {
        return userDao.queryUserById(id);
    }

    //    计时器，每5秒执行一次
//    @Scheduled(fixedDelay = 5000)
    public void timerTask() {
        String time = TextUtils.date2Str(new Date(), "HH:mm:ss");
        logger.info("每隔5秒执行：" + time);
    }
}
